package com.shop.cloud.controller.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shop.cloud.common.mybatis.BaseController;
import com.shop.cloud.domain.hongfu.GoodsOrder;
import com.shop.cloud.filter.CurrentUserId;
import com.shop.cloud.service.hongfu.IGoodsOrderService;
import com.shop.cloud.util.Page;
import com.shop.cloud.util.Response;
import com.shop.cloud.util.ResponseUtil;

import io.swagger.annotations.ApiOperation;
/**
 * 后台订单管理
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "order")
public class OrderController extends BaseController {

	@Autowired
	private IGoodsOrderService goodsOrderService;
	
	@ApiOperation(value = "获取订单列表", notes = "获取订单列表")
	@RequestMapping(value = "/getOrderList", method = RequestMethod.POST)
	@ResponseBody
	public Response getOrderList(@CurrentUserId Long userId, @RequestBody GoodsOrder goodsOrder){
		
		goodsOrder.setUserId(userId);
		goodsOrder.setOrderBy("GOODS_ORDER.create_time DESC");
		Page<GoodsOrder> data = goodsOrderService.handleMOrderList(goodsOrder);
		
		return ResponseUtil.ok(data);
	}
	
	@ApiOperation(value = "修改订单状态", notes = "修改订单状态")
	@RequestMapping(value = "/modifyOrder", method = RequestMethod.POST)
	@ResponseBody
	public Response modifyOrder(@RequestBody GoodsOrder goodsOrder){
		
		int data = goodsOrderService.handleOrderStatus(goodsOrder);
		
		return ResponseUtil.ok(data);
	}
	
	@ApiOperation(value = "获取订单详情", notes = "获取订单详情")
	@RequestMapping(value = "/getOrderByOne", method = RequestMethod.POST)
	@ResponseBody
	public Response getOrderByOne(@RequestBody GoodsOrder goodsOrder){
		
		GoodsOrder data = goodsOrderService.handleOrderDetail(goodsOrder);
		
		return ResponseUtil.ok(data);
	}
}